package com.moon.game.service;

import java.util.Timer;
import java.util.TimerTask;

import org.apache.log4j.Logger;

import com.moon.game.manager.PlayerMG;

/**
 * 玩家清理定时器
 * 
 */
public class CleanTask {
    private final static Logger logger = Logger.getLogger(CleanTask.class);
    private Timer timer = new Timer();
    public static CleanTask insc = new CleanTask();
    private CleanTask() {
	}
	
	public void init() {
		insc.start();
	}
    /**
     * 计时器启动 15分钟后开始执行,每分钟扫描一次
     */
    public void start() {
        timer.schedule(new TimerTask() {
            public void run() {
                try {
                    long start = System.currentTimeMillis();
                    PlayerMG.instance.logout();
                    long end = System.currentTimeMillis();
                    logger.warn("clean use time:" + (end - start));
                } catch (Exception e) {
                    logger.error("timer err：" + e.getMessage(), e);
                }
            }
        }, 15 * 60 * 1000, 1 * 60 * 1000);
    }
}
